package com.qdlc.p2p.dal.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.dal.common.dao.jpa.BaseDaoImpl;
import com.qdlc.p2p.dal.dao.AuthenticationLogDao;
import com.qdlc.p2p.dal.dto.AuthenticationLog;

/**
 * Created by lenovo on 2016/1/14.
 */
@Service("authenticationLogDao")
public class AuthenticationLogDaoImol extends BaseDaoImpl<AuthenticationLog> implements AuthenticationLogDao{

    @Override
    public int getStatus(long userId) {
        String jpql="select status from AuthenticationLog where userId=?1 order by status desc";
        Query query = em.createQuery(jpql).setParameter(1, userId);
        List status=query.getResultList();
        int result=0;
        if(!status.isEmpty()&&status!=null)
            result=Integer.parseInt(status.get(0)+"");
        return result;
    }

    @Override
    public Map<String,Object> getRemark(long userId,int count){
        Map<String,Object> remark=new HashMap<String, Object>();
        String jpql="select remark from AuthenticationLog where userId=?1 order by status";
        Query query = em.createQuery(jpql).setParameter(1, userId);
        List remarks=query.getResultList();
        remark.put("tppUserCustId",remarks.get(0));
        if(count>1) {
            String[] args = remarks.get(1).toString().split("\\|");
            remark.put("realName",args[0]);
            remark.put("cardId",args[1]);
            if(count>2)
                remark.put("sql",remarks.get(2));
        }
        return remark;

    }
}
